// Payroll account displayed if either Maturity instructions shown
// ---------------------------------------------------------------
!function ($) {
	$('[name=interest-option],[name=ST_RENEWAL_OPTION], [name=LT_RENEWAL_OPTION], [data-gic-mat], [name=NEWLTRSPGICINTEREST], [name=NEWLTRSPGICRENEWAL]').on('updated.dropdown.data-api', function (evt) {
		var $intOpt = $('[name=interest-option], [name=NEWLTRSPGICINTEREST]')
		, $matInt_ST = $('[name=ST_RENEWAL_OPTION]')
		, $matInt_LT = $('[name=LT_RENEWAL_OPTION], [name=NEWLTRSPGICRENEWAL]')
      // , $matOther = $('[data-gic-mat]')
      , $payout = $('#payout-account')

      console.log(parseInt($matInt_LT.val(), 10) === 2 || parseInt($matInt_ST.val(), 10) === 2 || parseInt($intOpt.val(), 10) === 2)

      $payout[(parseInt($matInt_LT.val(), 10) === 2 || parseInt($matInt_ST.val(), 10) === 2 || parseInt($intOpt.val(), 10) === 2) ? 'show' : 'hide']()
    })
}(window.jQuery)

// Industry and Occupation list auto
// -------------

!function ($) {
	var $industrySelect = $('#IndustryOccupation')
	, $occupationSelect = $('#Occupation')
	, $occupationDropdown = $occupationSelect.siblings('.dropdown-menu')
	, $occupationSelected = $occupationSelect.siblings('[data-toggle=dropdown]')
	, occupationDefault = $occupationSelected.html()
	, industryData = {
		"industry":[
		{
			"id":"ABIFA",
			"name":"Accounting, Banking, Insurance & Finance",
			"occupation":[
			{
				"id":"ACCCA",
				"name":"Accountant &ndash; CA/CMA/CGA"
			},
			{
				"id":"ACTNT",
				"name":"Accountant"
			},
			{
				"id":"ACTUR",
				"name":"Actuary"
			},
			{
				"id":"AUDIT",
				"name":"Auditor"
			},
			{
				"id":"BNKAD",
				"name":"Bank administrator"
			},
			{
				"id":"BOKPR",
				"name":"Bookkeeper"
			},
			{
				"id":"CFOFF",
				"name":"Chief financial officer"
			},
			{
				"id":"CACAC",
				"name":"Compliance analyst"
			},
			{
				"id":"CLADJ",
				"name":"Claims adjustor"
			},
			{
				"id":"CSREP",
				"name":"Customer service representative"
			},
			{
				"id":"ECONM",
				"name":"Economist"
			},
			{
				"id":"FINAN",
				"name":"Financial analyst"
			},
			{
				"id":"FINAD",
				"name":"Financial advisor"
			},
			{
				"id":"INSAG",
				"name":"Insurance agent"
			},
			{
				"id":"INVAN",
				"name":"Investment analyst"
			},
			{
				"id":"LOANO",
				"name":"Loan officer"
			},
			{
				"id":"MGRBK",
				"name":"Manager &ndash; banking"
			},
			{
				"id":"MGRFI",
				"name":"Manager &ndash; finance"
			},
			{
				"id":"MGRIN",
				"name":"Manager &ndash; insurance"
			},
			{
				"id":"MGRBR",
				"name":"Mortgage broker"
			},
			{
				"id":"SECTD",
				"name":"Securities trader"
			},
			{
				"id":"TRESR",
				"name":"Treasurer"
			},
			{
				"id":"UNDWR",
				"name":"Underwriter"
			}
			]
		},
		{
			"id":"AHRAH",
			"name":"Administration & Human resources",
			"occupation":[
			{
				"id":"ADMNA",
				"name":"Administrative assistant"
			},
			{
				"id":"CSREP",
				"name":"Customer service representative"
			},
			{
				"id":"GOCLK",
				"name":"General office clerk"
			},
			{
				"id":"FACSP",
				"name":"Facilities specialist"
			},
			{
				"id":"HRCON",
				"name":"Human resources consultant"
			},
			{
				"id":"MADSV",
				"name":"Manager &ndash; administrative services"
			},
			{
				"id":"MEDTR",
				"name":"Mediator"
			},
			{
				"id":"PURAG",
				"name":"Purchasing agent"
			},
			{
				"id":"RCPST",
				"name":"Receptionist"
			},
			{
				"id":"SECGU",
				"name":"Security guard"
			},
			{
				"id":"TELOP",
				"name":"Telephone operator"
			},
			{
				"id":"UNREP",
				"name":"Union representative"
			}
			]
		},
		{
			"id":"ANRAN",
			"name":"Agriculture & Natural resources",
			"occupation":[
			{
				"id":"ACQWK",
				"name":"Aquaculture worker"
			},
			{
				"id":"FRMWK",
				"name":"Farm worker"
			},
			{
				"id":"FSHWK",
				"name":"Fisheries worker"
			},
			{
				"id":"FSTWK",
				"name":"Forestry worker"
			},
			{
				"id":"MNEWK",
				"name":"Mine worker"
			},
			{
				"id":"MTLWK",
				"name":"Metals processing worker"
			},
			{
				"id":"PUPWK",
				"name":"Pulp and paper processing worker"
			}
			]
		},
		{
			"id":"ACACA",
			"name":"Arts & Communications",
			"occupation":[
			{
				"id":"ARTST",
				"name":"Artist"
			},
			{
				"id":"COMSP",
				"name":"Communications specialist"
			},
			{
				"id":"DESAC",
				"name":"Designer &ndash; arts & communications"
			},
			{
				"id":"EDITR",
				"name":"Editor"
			},
			{
				"id":"JORNT",
				"name":"Journalist"
			},
			{
				"id":"PERFA",
				"name":"Performance artist"
			},
			{
				"id":"PHOTR",
				"name":"Photographer"
			},
			{
				"id":"PRNTR",
				"name":"Printer"
			},
			{
				"id":"PRDAR",
				"name":"Producer &ndash; arts"
			},
			{
				"id":"PUBLR",
				"name":"Publisher"
			},
			{
				"id":"REPTR",
				"name":"Reporter"
			},
			{
				"id":"RESAC",
				"name":"Reseacher &ndash; arts & communications"
			},
			{
				"id":"TRNSR",
				"name":"Translator"
			},
			{
				"id":"WRITR",
				"name":"Writer"
			}
			]
		},
		{
			"id":"BMBMB",
			"name":"Business management",
			"occupation":[
			{
				"id":"CEOFF",
				"name":"Chief executive officer"
			},
			{
				"id":"COOFF",
				"name":"Chief operating officer"
			},
			{
				"id":"GMNGR",
				"name":"General manager"
			},
			{
				"id":"HRSPE",
				"name":"Human resources specialist"
			},
			{
				"id":"INVBK",
				"name":"Investment banker"
			},
			{
				"id":"MNGCO",
				"name":"Management consultant"
			},
			{
				"id":"PURMG",
				"name":"Purchasing manager"
			}
			]
		},
		{
			"id":"ETETE",
			"name":"Education & Training",
			"occupation":[
			{
				"id":"CHICW",
				"name":"Child care worker"
			},
			{
				"id":"EDASI",
				"name":"Educational assistant"
			},
			{
				"id":"EMPCO",
				"name":"Employment counsellor"
			},
			{
				"id":"LIBRA",
				"name":"Librarian"
			},
			{
				"id":"PRINC",
				"name":"Principal"
			},
			{
				"id":"PROFE",
				"name":"Professor"
			},
			{
				"id":"RESEA",
				"name":"Research assistant"
			},
			{
				"id":"SCHCO",
				"name":"School counsellor"
			},
			{
				"id":"TECHR",
				"name":"Teacher"
			},
			{
				"id":"TRANR",
				"name":"Trainer"
			}
			]
		},
		{
			"id":"ESGES",
			"name":"Emergency services & Government",
			"occupation":[
			{
				"id":"CITYC",
				"name":"City counsellor"
			},
			{
				"id":"CORRO",
				"name":"Corrections officer"
			},
			{
				"id":"EMEMT",
				"name":"Emergency medical technician"
			},
			{
				"id":"FIREF",
				"name":"Firefighter"
			},
			{
				"id":"GOVSO",
				"name":"Government services officer"
			},
			{
				"id":"GOVIN",
				"name":"Government inspector"
			},
			{
				"id":"JUDGE",
				"name":"Judge"
			},
			{
				"id":"MAYOR",
				"name":"Mayor"
			},
			{
				"id":"MEMOP",
				"name":"Member of parliament"
			},
			{
				"id":"MEMPP",
				"name":"Member of provincial parliament"
			},
			{
				"id":"MILOF",
				"name":"Military officer"
			},
			{
				"id":"MILSP",
				"name":"Military service person"
			},
			{
				"id":"PADIC",
				"name":"Paramedic"
			},
			{
				"id":"POLOF",
				"name":"Police officer"
			},
			{
				"id":"POLAN",
				"name":"Policy analyst"
			},
			{
				"id":"POSTW",
				"name":"Postal worker"
			},
			{
				"id":"SCHBT",
				"name":"School board trustee"
			},
			{
				"id":"SENTR",
				"name":"Senator"
			},
			{
				"id":"SOCWK",
				"name":"Social worker"
			},
			{
				"id":"URBPL",
				"name":"Urban planner"
			},
			{
				"id":"WASTE",
				"name":"Waste collection"
			}
			]
		},
		{
			"id":"EASEA",
			"name":"Engineering, Architecture & Science",
			"occupation":[
			{
				"id":"ARCHI",
				"name":"Architect"
			},
			{
				"id":"ASTMR",
				"name":"Astronomer"
			},
			{
				"id":"BIOLT",
				"name":"Biologist"
			},
			{
				"id":"CHENG",
				"name":"Chemical engineer"
			},
			{
				"id":"CHMIT",
				"name":"Chemist"
			},
			{
				"id":"CIVEN",
				"name":"Civil engineer"
			},
			{
				"id":"ELENG",
				"name":"Electrical engineer"
			},
			{
				"id":"GEOLT",
				"name":"Geologist"
			},
			{
				"id":"MATHM",
				"name":"Mathematician"
			},
			{
				"id":"MECEN",
				"name":"Mechanical engineer"
			},
			{
				"id":"PHYST",
				"name":"Physicist"
			},
			{
				"id":"RESCH",
				"name":"Researcher"
			},
			{
				"id":"SCIEN",
				"name":"Scientist"
			}
			]
		},
		{
			"id":"HFSTH",
			"name":"Hospitality, Food service & Tourism",
			"occupation":[
			{
				"id":"EVEPL",
				"name":"Events planner"
			},
			{
				"id":"FODSW",
				"name":"Food services worker"
			},
			{
				"id":"HOSSW",
				"name":"Hospitality services worker"
			},
			{
				"id":"HOTMG",
				"name":"Hotel manager"
			},
			{
				"id":"RESMG",
				"name":"Restaurant manager"
			},
			{
				"id":"TRAVA",
				"name":"Travel agent"
			}
			]
		},
		{
			"id":"ITITI",
			"name":"Information technology",
			"occupation":[
			{
				"id":"COMCO",
				"name":"Computer consultant"
			},
			{
				"id":"DCMNG",
				"name":"Data centre manager"
			},
			{
				"id":"INFSA",
				"name":"Information systems analyst"
			},
			{
				"id":"INFSM",
				"name":"Information systems manager"
			},
			{
				"id":"ITPMR",
				"name":"Information technology project manager"
			},
			{
				"id":"PRGMR",
				"name":"Programmer"
			},
			{
				"id":"SOFEN",
				"name":"Software engineer"
			},
			{
				"id":"TELSP",
				"name":"Telecommunications specialist"
			},
			{
				"id":"WEBDS",
				"name":"Web designer"
			}
			]
		},
		{
			"id":"LSLSL",
			"name":"Legal services",
			"occupation":[
			{
				"id":"ADMST",
				"name":"Administrative assistant"
			},
			{
				"id":"ARTSL",
				"name":"Articling student &ndash; law"
			},
			{
				"id":"COROF",
				"name":"Court officer"
			},
			{
				"id":"JUDGJ",
				"name":"Judge"
			},
			{
				"id":"JUSOP",
				"name":"Justice of the peace"
			},
			{
				"id":"LAWCK",
				"name":"Law clerk"
			},
			{
				"id":"LAWYR",
				"name":"Lawyer"
			},
			{
				"id":"NOTAR",
				"name":"Notary"
			},
			{
				"id":"PALEG",
				"name":"Paralegal"
			},
			{
				"id":"PRBOF",
				"name":"Probation officer"
			}
			]
		},
		{
			"id":"MCGSM",
			"name":"Medical & Caregiving services",
			"occupation":[
			{
				"id":"ADIGT",
				"name":"Audiologist"
			},
			{
				"id":"CHIPR",
				"name":"Chiropractor"
			},
			{
				"id":"DAYCW",
				"name":"Day care worker"
			},
			{
				"id":"DENTI",
				"name":"Dentist"
			},
			{
				"id":"DNTEC",
				"name":"Dental technician"
			},
			{
				"id":"DIETN",
				"name":"Dietician"
			},
			{
				"id":"DRGPR",
				"name":"Doctor &ndash; general practitioner"
			},
			{
				"id":"DRSPE",
				"name":"Doctor &ndash; specialist"
			},
			{
				"id":"FUHOW",
				"name":"Funeral home worker"
			},
			{
				"id":"HCCON",
				"name":"Health care counsellor"
			},
			{
				"id":"HOMEM",
				"name":"Homemaker"
			},
			{
				"id":"HOSAD",
				"name":"Hospital administrator"
			},
			{
				"id":"MASTH",
				"name":"Massage therapist"
			},
			{
				"id":"MEDTC",
				"name":"Medical technician"
			},
			{
				"id":"MIDWF",
				"name":"Midwife"
			},
			{
				"id":"OCCTH",
				"name":"Occupational therapist"
			},
			{
				"id":"OPTST",
				"name":"Optometrist"
			},
			{
				"id":"PARIC",
				"name":"Paramedic"
			},
			{
				"id":"PHAST",
				"name":"Pharmacist"
			},
			{
				"id":"PHYSO",
				"name":"Physiotherapist"
			},
			{
				"id":"PSYCH",
				"name":"Psychologist"
			},
			{
				"id":"NANNY",
				"name":"Nanny"
			},
			{
				"id":"NURSE",
				"name":"Nurse"
			},
			{
				"id":"RESTH",
				"name":"Respiratory therapist"
			},
			{
				"id":"SOSEW",
				"name":"Social services worker"
			},
			{
				"id":"THMES",
				"name":"Therapist &ndash; medical services"
			},
			{
				"id":"VETER",
				"name":"Veterinarian"
			}
			]
		},
		{
			"id":"RESRE",
			"name":"Real estate services",
			"occupation":[
			{
				"id":"LANSU",
				"name":"Land surveyor"
			},
			{
				"id":"MORTB",
				"name":"Mortgage broker"
			},
			{
				"id":"PROPA",
				"name":"Property assessor"
			},
			{
				"id":"RAGNT",
				"name":"Real estate agent"
			},
			{
				"id":"RLESA",
				"name":"Real estate assessor"
			}
			]
		},
		{
			"id":"RVRVR",
			"name":"Religious vocation",
			"occupation":[
			{
				"id":"CHAPL",
				"name":"Chaplain"
			},
			{
				"id":"CLRGY",
				"name":"Clergy"
			},
			{
				"id":"IMAMM",
				"name":"Imam"
			},
			{
				"id":"MINTR",
				"name":"Minister"
			},
			{
				"id":"NUNNN",
				"name":"Nun"
			},
			{
				"id":"PRIST",
				"name":"Priest"
			},
			{
				"id":"RABBI",
				"name":"Rabbi"
			},
			{
				"id":"RELWK",
				"name":"Religious worker"
			}
			]
		},
		{
			"id":"SMRSM",
			"name":"Sales, Marketing & Retail services",
			"occupation":[
			{
				"id":"CASHR",
				"name":"Cashier"
			},
			{
				"id":"HAIRD",
				"name":"Hairdresser"
			},
			{
				"id":"JEWEL",
				"name":"Jeweler"
			},
			{
				"id":"MKTRP",
				"name":"Marketing representative"
			},
			{
				"id":"RTLSW",
				"name":"Retail services worker"
			},
			{
				"id":"SALEP",
				"name":"Salesperson"
			},
			{
				"id":"TELMK",
				"name":"Telemarketer"
			}
			]
		},
		{
			"id":"SLSLS",
			"name":"Sports & Leisure",
			"occupation":[
			{
				"id":"COACH",
				"name":"Coach"
			},
			{
				"id":"PERSW",
				"name":"Personal services worker"
			},
			{
				"id":"PERTR",
				"name":"Personal trainer"
			},
			{
				"id":"PROAT",
				"name":"Professional athlete"
			},
			{
				"id":"SPTIN",
				"name":"Sports instructor"
			},
			{
				"id":"SPTMG",
				"name":"Sports manager"
			},
			{
				"id":"SPTOF",
				"name":"Sports official"
			},
			{
				"id":"SPTTH",
				"name":"Sports therapist"
			}
			]
		},
		{
			"id":"SRHUC",
			"name":"Student, Retired, Homemaker, Unemployed, Child",
			"occupation":[
			{
				"id":"CHILD",
				"name":"Child"
			},
			{
				"id":"HMKER",
				"name":"Homemaker"
			},
			{
				"id":"RETRD",
				"name":"Retired"
			},
			{
				"id":"STDNT",
				"name":"Student"
			},
			{
				"id":"UNEMP",
				"name":"Unemployed"
			}
			]
		},
		{
			"id":"TCMTC",
			"name":"Trades, Construction & Manufacturing",
			"occupation":[
			{
				"id":"BKLYR",
				"name":"Bricklayer"
			},
			{
				"id":"CARPT",
				"name":"Carpenter"
			},
			{
				"id":"CRANE",
				"name":"Crane operator"
			},
			{
				"id":"ELECT",
				"name":"Electrician"
			},
			{
				"id":"GENCO",
				"name":"General contractor"
			},
			{
				"id":"HEOPR",
				"name":"Heavy equipment operator"
			},
			{
				"id":"LABRR",
				"name":"Labourer"
			},
			{
				"id":"LANDS",
				"name":"Landscaper"
			},
			{
				"id":"MACHT",
				"name":"Machinist"
			},
			{
				"id":"MANFW",
				"name":"Manufacturing worker"
			},
			{
				"id":"MECNC",
				"name":"Mechanic"
			},
			{
				"id":"METAL",
				"name":"Metal worker"
			},
			{
				"id":"PANTR",
				"name":"Painter"
			},
			{
				"id":"PIPEF",
				"name":"Pipefitter"
			},
			{
				"id":"PLUMB",
				"name":"Plumber"
			},
			{
				"id":"TDIEM",
				"name":"Tool and die maker"
			},
			{
				"id":"TDPER",
				"name":"Tradesperson"
			}
			]
		},
		{
			"id":"TUTUT",
			"name":"Transportation & Utilities",
			"occupation":[
			{
				"id":"AIRTC",
				"name":"Air traffic controller"
			},
			{
				"id":"BAGHA",
				"name":"Baggage handler"
			},
			{
				"id":"BSDRV",
				"name":"Bus driver"
			},
			{
				"id":"DELDR",
				"name":"Delivery driver"
			},
			{
				"id":"FLGTA",
				"name":"Flight attendant"
			},
			{
				"id":"MECHC",
				"name":"Mechanic"
			},
			{
				"id":"PILOT",
				"name":"Pilot"
			},
			{
				"id":"RMTWK",
				"name":"Railway/Marine transport worker"
			},
			{
				"id":"SRUTI",
				"name":"Service representative &ndash; utilities"
			},
			{
				"id":"TAXID",
				"name":"Taxi driver"
			},
			{
				"id":"TRDIS",
				"name":"Transportation dispatcher"
			},
			{
				"id":"TRUKD",
				"name":"Truck driver"
			}
			]
		}
		]
	}

	, industryUpdate = function (evt) {
		var industryMap = industryData.industry
		, choice = this.value

        $occupationSelected.html(occupationDefault) // reset Bootstrap dropdown selection

        for (var x = 0; x < industryMap.length; x++) { // iterate through available industries
          if (choice === industryMap[x].id) { // proceed if selected industry id matches in list
          	var occupationMap = industryMap[x].occupation
          	, occupationOptions = []
          	, occupationItems = []

            for (var y = 0; y < occupationMap.length; y++) { // iterate through available occupations that fall under selected industry
              occupationItems.push('<li><a href="#" data-value="' + occupationMap[y].id + '">' + occupationMap[y].name + '</a></li>') // build bootstrap dropdown occupation list
              occupationOptions.push('<option value="' + occupationMap[y].id + '">' + occupationMap[y].name + '</option>') // build select box occupation list
            }
            $occupationSelect.html(occupationOptions.join('')); // populate the select box
            $occupationDropdown.html(occupationItems.join('')); // populate the bootstrap dropdown
            //$("#HideOccupation").show();
            $occupationSelect[method](classToGet).removeClass('is-hidden')
            break // break out of the loop to avoid unnecessary looping
          }
        }
      }

      var method = $occupationSelect.parents('.control-group')[0] ? 'parents' : 'parent'
      , classToGet = method === 'parents' ? '.control-group' : null

      // TQA00390848
      // Description: on Mortgage App income section, occupation dropdown gets hidden by default
      // Solution: in order to preserve functionality used anywhere else, a condtional has been introduced to see if the industry select is available, if not then don't hide the occupation section
      if (!!$industrySelect[0]) {
      	$occupationSelect[method](classToGet).addClass('is-hidden')
    	}

      $industrySelect.on('change updated.dropdown', industryUpdate);


    }(window.jQuery)


// BusinessIndustry & Business
// -------------

!function ($) {
	var $businessIndustrySelect = $('#BusinessIndustry')
	, $businessSelect = $('#Business')
	, $businessDropdown = $businessSelect.siblings('.dropdown-menu')
	, $businessSelected = $businessSelect.siblings('[data-toggle=dropdown]')
	, businessDefault = $businessSelected.html()
	, businessData = {
		"industry":[
		{
			"id":"ACCFS",
			"name":"Accommodation & food service",
			"business":[
			{
				"id":"BANQH",
				"name":"Banquet hall"
			},
			{
				"id":"BARBA",
				"name":"Bar"
			},
			{
				"id":"CASIH",
				"name":"Caterer"
			},
			{
				"id":"CATER",
				"name":"Casino hotel"
			},
			{
				"id":"CONFF",
				"name":"Conference facility"
			},
			{
				"id":"FSCON",
				"name":"Food service contractor"
			},
			{
				"id":"HOTEL",
				"name":"Hotel"
			},
			{
				"id":"MOTEL",
				"name":"Motel"
			},
			{
				"id":"NIGTC",
				"name":"Night club"
			},
			{
				"id":"RESNT",
				"name":"Restaurant"
			}
			]
		},
		{
			"id":"ADRWI",
			"name":"Administration, retail & wholesale industries",
			"business":[
			{
				"id":"CHCAS",
				"name":"Cheque cashing service"
			},
			{
				"id":"CLENS",
				"name":"Cleaning service"
			},
			{
				"id":"COURS",
				"name":"Courier service"
			},
			{
				"id":"EBISE",
				"name":"Engineering & building inspection service"
			},
			{
				"id":"ENVCS",
				"name":"Environmental consulting service"
			},
			{
				"id":"FACSS",
				"name":"Facilities support service"
			},
			{
				"id":"IMEXS",
				"name":"Import/Export service"
			},
			{
				"id":"LANSS",
				"name":"Landscaping service"
			},
			{
				"id":"LOBFM",
				"name":"Lobbying firm"
			},
			{
				"id":"MGCOS",
				"name":"Management consulting service"
			},
			{
				"id":"OFFAS",
				"name":"Office administrative service"
			},
			{
				"id":"PSTCS",
				"name":"Pest control service"
			},
			{
				"id":"RESSP",
				"name":"Residential service provider"
			},
			{
				"id":"RETGM",
				"name":"Retail trade - General merchandise"
			},
			{
				"id":"RETRA",
				"name":"Retail trade - Automotive"
			},
			{
				"id":"RETRS",
				"name":"Retail trade - Specialty"
			},
			{
				"id":"RTGRC",
				"name":"Retail trade - Grocery store / Convenience store"
			},
			{
				"id":"RTPES",
				"name":"Retail trade - Personal services"
			},
			{
				"id":"SECUS",
				"name":"Security service"
			},
			{
				"id":"STRRE",
				"name":"Storage rental"
			},
			{
				"id":"WAGCS",
				"name":"Wholesale trade - Agricultural & chemical supplies"
			},
			{
				"id":"WBUMS",
				"name":"Wholesale trade - Building & machinery supplies"
			},
			{
				"id":"WGENS",
				"name":"Wholesale trade - General supplies"
			}   
			]
		},
		{
			"id":"AGFFH",
			"name":"Agriculture, forestry, fishing & hunting",
			"business":[
			{
				"id":"ANMLP",
				"name":"Animal production"
			},
			{
				"id":"CROPP",
				"name":"Crop production"
			},
			{
				"id":"FISHU",
				"name":"Fishing & hunting"
			},
			{
				"id":"FORLG",
				"name":"Forestry & logging"
			}
			]
		},
		{
			"id":"ACERS",
			"name":"Arts, culture, entertainment, recreation & sport",
			"business":[
			{
				"id":"ADLTE",
				"name":"Adult entertainment"
			},
			{
				"id":"AMUSC",
				"name":"Amusement centre"
			},
			{
				"id":"CASNO",
				"name":"Casino"
			},
			{
				"id":"GAMBG",
				"name":"Gambling"
			},
			{
				"id":"MPINS",
				"name":"Motion picture industry services"
			},
			{
				"id":"PERAC",
				"name":"Performing arts company"
			},
			{
				"id":"RADBR",
				"name":"Radio broadcasting"
			},
			{
				"id":"RECCB",
				"name":"Recreational club"
			},
			{
				"id":"SPRTT",
				"name":"Sports team"
			},
			{
				"id":"THEAT",
				"name":"Theatre"
			},
			{
				"id":"TVBRO",
				"name":"Television broadcasting"
			}
			]
		},
		{
			"id":"CNFPO",
			"name":"Charitable and not for profit organisations",
			"business":[
			{
				"id":"CLUBC",
				"name":"Club"
			},
			{
				"id":"GRPOR",
				"name":"Group/ Organisation"
			},
			{
				"id":"NFPRO",
				"name":"Not for profit (other than a charitable organisation)"
			},
			{
				"id":"NREGC",
				"name":"Non-registered charity"
			},
			{
				"id":"REGCH",
				"name":"Registered charity"
			}
			]
		},
		{
			"id":"CONMA",
			"name":"Construction & manufacturing",
			"business":[
			{
				"id":"COMEC",
				"name":"Commercial construction"
			},
			{
				"id":"CPPMA",
				"name":"Chemical, petroleum & plastics  manufacturing"
			},
			{
				"id":"ECMAN",
				"name":"Electrical component manufacturing"
			},
			{
				"id":"EQUMA",
				"name":"Equipment manufacturing"
			},
			{
				"id":"FURNM",
				"name":"Furniture manufacturing"
			},
			{
				"id":"GENMA",
				"name":"General manufacturing"
			},
			{
				"id":"HCECO",
				"name":"Heavy & civil engineering construction"
			},
			{
				"id":"HOMBU",
				"name":"Homebuilder"
			},
			{
				"id":"MEMAM",
				"name":"Metal & machinery manufacturing"
			},
			{
				"id":"SPTCO",
				"name":"Specialty trade contractor"
			}
			]
		},
		{
			"id":"EDUHC",
			"name":"Education & health care",
			"business":[
			{
				"id":"ALHEC",
				"name":"Alternative health care"
			},
			{
				"id":"DCCEN",
				"name":"Day care center"
			},
			{
				"id":"DIALA",
				"name":"Diagnostic laboratory"
			},
			{
				"id":"DRINS",
				"name":"Driving instruction"
			},
			{
				"id":"EHFTR",
				"name":"Exercise, health & fitness training"
			},
			{
				"id":"FITNC",
				"name":"Fitness centre"
			},
			{
				"id":"HHCSE",
				"name":"Home health care services"
			},
			{
				"id":"LANIN",
				"name":"Language instruction"
			},
			{
				"id":"LTCFA",
				"name":"Long term care facility"
			},
			{
				"id":"MEDIL",
				"name":"Medical and diagnostic laboratories"
			},
			{
				"id":"MPESE",
				"name":"Medical products, equipment & services"
			},
			{
				"id":"MEDEC",
				"name":"Medical or dental center"
			},
			{
				"id":"MESEP",
				"name":"Medical service provider"
			},
			{
				"id":"NURSC",
				"name":"Nursery school"
			},
			{
				"id":"PHARM",
				"name":"Pharmacy"
			},
			{
				"id":"PPREH",
				"name":"Physiotherapy & physical rehabilitation"
			},
			{
				"id":"PRIVS",
				"name":"Private school"
			},
			{
				"id":"RELSC",
				"name":"Religious school"
			},
			{
				"id":"SPEPS",
				"name":"Special purpose school"
			},
			{
				"id":"TECTS",
				"name":"Technical or trade school"
			},
			{
				"id":"TUTOS",
				"name":"Tutoring service"
			}
			]
		},
		{
			"id":"FILRE",
			"name":"Finance, insurance, leasing & real estatee",
			"business":[
			{
				"id":"BANCO",
				"name":"Banking - Commercial"
			},
			{
				"id":"BANRE",
				"name":"Banking - Retail"
			},
			{
				"id":"COMDE",
				"name":"Condominium corporation"
			},
			{
				"id":"CONDC",
				"name":"Commodities dealer"
			},
			{
				"id":"EQIRL",
				"name":"Equipment rental & leasing"
			},
			{
				"id":"INSBR",
				"name":"Insurance broker"
			},
			{
				"id":"INVMG",
				"name":"Investment management"
			},
			{
				"id":"LEAFI",
				"name":"Lease financing"
			},
			{
				"id":"LOANB",
				"name":"Loan broker"
			},
			{
				"id":"PRKLO",
				"name":"Parking lot operator"
			},
			{
				"id":"PROMC",
				"name":"Property manager - Commercial"
			},
			{
				"id":"PROMR",
				"name":"Property manager - Residential"
			},
			{
				"id":"RELEB",
				"name":"Real estate broker"
			},
			{
				"id":"STOKB",
				"name":"Stock broker"
			}
			]
		},
		{
			"id":"GOVMT",
			"name":"Government",
			"business":[
			{
				"id":"CORSE",
				"name":"Correctional services"
			},
			{
				"id":"CORTL",
				"name":"Courts of law"
			},
			{
				"id":"FEDPA",
				"name":"Federal public administration"
			},
			{
				"id":"IMIGS",
				"name":"Immigration services"
			},
			{
				"id":"LABES",
				"name":"Labour & employment services"
			},
			{
				"id":"LMPPA",
				"name":"Local, municipal and provincial public administration"
			},
			{
				"id":"POLIC",
				"name":"Police services"
			}

			]
		},
		{
			"id":"ICEIN",
			"name":"Information, computer & electronics industries",
			"business":[
			{
				"id":"COMSE",
				"name":"Communications Services & Equipment"
			},
			{
				"id":"COMPE",
				"name":"Computer Services & Equipment"
			},
			{
				"id":"COPSD",
				"name":"Computer Systems Design"
			},
			{
				"id":"DATPS",
				"name":"Data Processing Services"
			},
			{
				"id":"DIRMS",
				"name":"Direct Mail Services"
			},
			{
				"id":"DOCTS",
				"name":"Document Services"
			},
			{
				"id":"ELESE",
				"name":"Electronics Services & Equipment"
			},
			{
				"id":"INTSE",
				"name":"Internet Services"
			},
			{
				"id":"PRNTG",
				"name":"Printing"
			},
			{
				"id":"PUBLS",
				"name":"Publishing"
			},
			{
				"id":"WDESN",
				"name":"Web Design"
			}
			]
		},
		{
			"id":"MOGUT",
			"name":"Mining and oil & gas and utilities",
			"business":[
			{
				"id":"EPGTD",
				"name":"Electric Power Generation, Transmission & Distribution"
			},
			{
				"id":"MINQU",
				"name":"Mining & Quarrying"
			},
			{
				"id":"NGDIS",
				"name":"Natural Gas Distribution"
			},
			{
				"id":"OGEXT",
				"name":"Oil and Gas Extraction"
			},
			{
				"id":"WSOSY",
				"name":"Water, Sewage & Other Systems"
			}
			]
		},
		{
			"id":"PROSA",
			"name":"Professional services & agencies",
			"business":[
			{
				"id":"ACCFM",
				"name":"Accounting Firm"
			},
			{
				"id":"ADVAG",
				"name":"Advertising Agency"
			},
			{
				"id":"ARCFM",
				"name":"Architecture Firm"
			},
			{
				"id":"BPSER",
				"name":"Bookkeeping & Payroll Service"
			},
			{
				"id":"EMPAG",
				"name":"Employment Agency"
			},
			{
				"id":"LEASV",
				"name":"Leasing Services"
			},
			{
				"id":"LEGFM",
				"name":"Legal Firm"
			},
			{
				"id":"MKSEV",
				"name":"Marketing & Sales Services"
			},
			{
				"id":"MODTA",
				"name":"Modelling / Talent Agency"
			},
			{
				"id":"PROSF",
				"name":"Professional Services Firm"
			},
			{
				"id":"TVLAG",
				"name":"Travel Agency"
			}
			]
		},
		{
			"id":"TRANN",
			"name":"Transportation",
			"business":[
			{
				"id":"ACPJR",
				"name":"Air Charter & Private Jet Rental"
			},
			{
				"id":"AIRLN",
				"name":"Airline"
			},
			{
				"id":"BOATR",
				"name":"Boat Rental"
			},
			{
				"id":"BUSLN",
				"name":"Bus Line"
			},
			{
				"id":"CTREN",
				"name":"Car & Truck Rental"
			},
			{
				"id":"FREIS",
				"name":"Freight Shipping"
			},
			{
				"id":"LIMSV",
				"name":"Limousine Service"
			},
			{
				"id":"MOVCY",
				"name":"Moving Company"
			},
			{
				"id":"RAISV",
				"name":"Rail Services"
			},
			{
				"id":"STFCC",
				"name":"Storage, Freight & Cargo Containers"
			},
			{
				"id":"TRPSV",
				"name":"Transportation Service"
			},
			{
				"id":"TRUKG",
				"name":"Trucking"
			},
			{
				"id":"TXISV",
				"name":"Taxi Service"
			}
			]
		},
		{
			"id":"SLSLS",
			"name":"Sports & Leisure",
			"business":[
			{
				"id":"COACH",
				"name":"Coach"
			},
			{
				"id":"PERSW",
				"name":"Personal services worker"
			},
			{
				"id":"PERTR",
				"name":"Personal trainer"
			},
			{
				"id":"PROAT",
				"name":"Professional athlete"
			},
			{
				"id":"SPTIN",
				"name":"Sports instructor"
			},
			{
				"id":"SPTMG",
				"name":"Sports manager"
			},
			{
				"id":"SPTOF",
				"name":"Sports official"
			},
			{
				"id":"SPTTH",
				"name":"Sports therapist"
			}
			]
		},
		{
			"id":"SRHUC",
			"name":"Student, Retired, Homemaker, Unemployed, Child",
			"business":[
			{
				"id":"CHILD",
				"name":"Child"
			},
			{
				"id":"HMKER",
				"name":"Homemaker"
			},
			{
				"id":"RETRD",
				"name":"Retired"
			},
			{
				"id":"STDNT",
				"name":"Student"
			},
			{
				"id":"UNEMP",
				"name":"Unemployed"
			}
			]
		},
		{
			"id":"TCMTC",
			"name":"Trades, Construction & Manufacturing",
			"business":[
			{
				"id":"BKLYR",
				"name":"Bricklayer"
			},
			{
				"id":"CARPT",
				"name":"Carpenter"
			},
			{
				"id":"CRANE",
				"name":"Crane operator"
			},
			{
				"id":"ELECT",
				"name":"Electrician"
			},
			{
				"id":"GENCO",
				"name":"General contractor"
			},
			{
				"id":"HEOPR",
				"name":"Heavy equipment operator"
			},
			{
				"id":"LABRR",
				"name":"Labourer"
			},
			{
				"id":"LANDS",
				"name":"Landscaper"
			},
			{
				"id":"MACHT",
				"name":"Machinist"
			},
			{
				"id":"MANFW",
				"name":"Manufacturing worker"
			},
			{
				"id":"MECNC",
				"name":"Mechanic"
			},
			{
				"id":"METAL",
				"name":"Metal worker"
			},
			{
				"id":"PANTR",
				"name":"Painter"
			},
			{
				"id":"PIPEF",
				"name":"Pipefitter"
			},
			{
				"id":"PLUMB",
				"name":"Plumber"
			},
			{
				"id":"TDIEM",
				"name":"Tool and die maker"
			},
			{
				"id":"TDPER",
				"name":"Tradesperson"
			}
			]
		},
		{
			"id":"TUTUT",
			"name":"Transportation & Utilities",
			"business":[
			{
				"id":"AIRTC",
				"name":"Air traffic controller"
			},
			{
				"id":"BAGHA",
				"name":"Baggage handler"
			},
			{
				"id":"BSDRV",
				"name":"Bus driver"
			},
			{
				"id":"DELDR",
				"name":"Delivery driver"
			},
			{
				"id":"FLGTA",
				"name":"Flight attendant"
			},
			{
				"id":"MECHC",
				"name":"Mechanic"
			},
			{
				"id":"PILOT",
				"name":"Pilot"
			},
			{
				"id":"RMTWK",
				"name":"Railway/Marine transport worker"
			},
			{
				"id":"SRUTI",
				"name":"Service representative &ndash; utilities"
			},
			{
				"id":"TAXID",
				"name":"Taxi driver"
			},
			{
				"id":"TRDIS",
				"name":"Transportation dispatcher"
			},
			{
				"id":"TRUKD",
				"name":"Truck driver"
			}
			]
		}
		]
	}

	, businessUpdate = function (evt) {
		var businessMap = businessData.industry
		, choice = this.value

        $businessSelected.html(businessDefault) // reset Bootstrap dropdown selection

        for (var x = 0; x < businessMap.length; x++) { // iterate through available industries
          if (choice === businessMap[x].id) { // proceed if selected industry id matches in list
          	var businessMap = businessMap[x].business
          	, businessOptions = []
          	, businessItems = []

            for (var y = 0; y < businessMap.length; y++) { // iterate through available occupations that fall under selected industry
              businessItems.push('<li><a href="#" data-value="' + businessMap[y].id + '">' + businessMap[y].name + '</a></li>') // build bootstrap dropdown occupation list
              businessOptions.push('<option value="' + businessMap[y].id + '">' + businessMap[y].name + '</option>') // build select box business list
            }
            $businessSelect.html(businessOptions.join('')); // populate the select box
            $businessDropdown.html(businessItems.join('')); // populate the bootstrap dropdown
            //$("#Hidebusiness").show();
            $businessSelect[method](classToGet).removeClass('is-hidden')
            break // break out of the loop to avoid unnecessary looping
          }
        }
      }

      var method = $businessSelect.parents('.control-group')[0] ? 'parents' : 'parent'
      , classToGet = method === 'parents' ? '.control-group' : null

      $businessSelect[method](classToGet).addClass('is-hidden')

      $businessIndustrySelect.on('change updated.dropdown', businessUpdate);


    }(window.jQuery)

// total tally in table
// --------------------------
!function ($) {
	var target
	, total

	, formatCurrency = function (value) {
		var lang = $('html').prop('lang')
		, thousandSeperator = lang === 'en-CA' ? ',' : ' '
		, decimalSeperator = lang === 'en-CA' ? '.' : ','
		, prefix = lang === 'en-CA' ? '$' : ''
		, suffix = lang === 'fr-CA' ? ' $' : ''

		return prefix + value.toFixed(2).replace(/(\d)(?=(\d{3})+\b)/g, '$1' + thousandSeperator).replace(/\./g, decimalSeperator) + suffix
	}
	, tallyLoop = function () {
		if ($(this).data('target') !== target) {
			return
		}
		total += parseFloat($(this).val()) || 0
	}
	, tallyInputs = function (evt) {
		target = $(this).data('target')
		total = 0
		$('input[data-tally]').each(tallyLoop)
		$(target).text(formatCurrency(total))
	}

	$(document).on('keyup change', 'input[data-tally]', tallyInputs)
}(window.jQuery)


// Postal code lookup feature
// --------------------------
+function ($) {
	var success = false
	, modal = document.createElement('div')
	, modalContainer = document.createElement('div')

	, toTitleCase = function (str) {
		return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
	}

	, getPostalCode = function (evt) {
		if (!$(this).valid() || success) {
			return
		}

		success = true

		var postal = this.value

		$.ajax({
            //url: '/INGDirect.html' // Production/ SIT
            url: 'json/address.json' // Local dev
            , data: {
            	command: 'displayAjaxResponse'
            	, ValidateElement: 'PostalCode'
            	, CONTROLCLASS: 'displayDepositApplicantPrimary'
            	, PostalCode: postal
            }
            , dataType: 'json'
            , success: displayPostalCodeResults
            , error: throwError
          })
	}

	, displayPostalCodeResults = function (message) {
		var html = ''
		for(var a = 0; a < message.address.length; a++) {
			var address = message.address[a]
			, street = toTitleCase(address.street)
			, city = toTitleCase(address.city)
			, province = address.province

			html += '<p><a href=# data-dismiss="modal" data-street="' + street + '" data-city="' + city + '" data-province="' + province + '">' +
			street + ', ' +
			city + ', ' +
			province +
			'</a></p>'
		}

		$('#address-lookup #address-list')
		.html(html)
		.on('click', setAddress)

		$('#address-lookup').modal('show')
	}

	, setAddress = function (evt) {
		var choice = $(evt.target).data()
		, province = $('[data-name=Province]').siblings('.dropdown-menu').find('[data-value=' + choice.province + ']').text()
		, caret = '&nbsp;<span class="icon-caret-down"></span>'

		$('[name=Address]').val(choice.street)
		$('[name=City]').val(choice.city)
		$('[data-name=Province]').text(province).append(caret)
		$('[name=Province]').val(choice.province)
	}

	, throwError = function (xhr,  status, error) {
		console.error(xhr)
		console.error(status)
		console.error(error)
	}

	, resetPostalState = function (evt) {
		success = false
	}


  // Build postal code lookkup modal window
  // --------------------------------------
  $(modalContainer)
  .addClass('modal-container')
  .load('modals/AddressLookup.html #modal-content')

  $(modal)
  .attr({
  	'id': 'address-lookup'
  	, 'class': 'modal hide fade'
  	, 'tabindex': '-1'
  	, 'role': 'dialog'
  	, 'aria-hidden': 'true'
  })
  .append(modalContainer)
  .appendTo(document.body)


  // Event handlers
  // --------------
  $('#address-lookup').on('hide', resetPostalState)
  $('[name=PostalCode]').on('keyup', getPostalCode)
}(window.jQuery)


// Disable other form elements
// ---------------------------
/*
  Disables the submit button on hidden input change.

  1. Add data-value="var" to the hidden input 
  2. Add data-disable-target="var" to the input to be disabled (the submit button)
  */
  !function ($) {
  	'use strict';


  	var disableInputs = function() {
  		$('[data-disable]').each(function(){
  			var $this = $(this)
      // get hidden input
      , checkInput = $this.parent().attr('data-name')
      // , $checkInput = $('[name="' + checkInput + '"]')
      , $checkInput = $('input#' + checkInput)

      // get target to disable
      , disableTarget = $this.attr('data-disable')
      , $disableTarget = $('[data-disable-target="' + disableTarget + '"]')

      console.log('loads')

      $checkInput.change(function(){
      	if($checkInput.val() == $this.attr('data-value')) {        
      		$disableTarget.attr('disabled','disabled')
      	} else {
      		$disableTarget.removeAttr('disabled')
      	}
      })
    })
  	}

  // Event handlers
  disableInputs()
  $('.btn-group input').on('change', disableInputs)

}(window.jQuery)

// Business Enrollment Function
// -------------

// !function ($) {
// 	var $addOwnerTrigger = $('[data-add="newowner"]')
// 	,	$ownerForm = $('[data-owner="form"]').first().clone()
// 	var inc = 1
// 	, addOwnerForm = function (evt) {
// 		evt.preventDefault()
// 		inc = inc + 1
// 		var x = $('#Owner1Percentage').val()
// 		, y = 100
// 		, z = 25
// 		, $newOwner = $ownerForm.clone().attr('data-index', inc)

// 		if( x > y || x < z){
// 			console.log("not happening")
// 		} else {

// 		$newOwner.find('input,select').each(function () {
// 			if ($(this).attr('type') === 'text') {
// 				$(this).val('');
// 			}
// 			var name = $(this).attr('name')
// 			$(this).attr({
//             'name': name + inc
//             , 'id': name + inc
//           })
// 		})

// 		// $newowner.find('label').each(function () {
// 		// 	var labelfor = $(this).attr('for')
// 		// 	$(this).attr({
// 		// 		'for': labelfor + inc
// 		// 	})
// 		// })

// 		$(this).parents('[data-owner="form"]').after($newOwner)
// 		}	
// 	}

// 	$('#person').each(function(evt){
// 		$(this).on('click', '[data-add="newowner"]', addOwnerForm)
// 	})


// }(window.jQuery)
